from http.client import responses

import requests

class ApiRequestTool:
    #请求地址
    def __init__(self,base_url):
        self.base_url=base_url
        self.session=requests.Session()

    #封装请求方式
    def get(self,path,params=None,head=None):
        full_url=self.base_url+path
        response = self.session.get(full_url,params=params,headers=head)
        return response.status_code,response.text,response.json()

    def post(self,path,data=None,head=None,params=None,json=None):
        full_url=self.base_url+path
        response = self.session.post(full_url,data=data,headers=head,params=params,json=json)
        return response.status_code,response.text,response.json()

    def put(self,path,data=None,head=None,json=None):
        full_url=self.base_url+path
        response = self.session.put(full_url,data=data,headers=head,json=json)
        return response.status_code,response.text,response.json()

    def delete(self,path,params=None,head=None):
        full_url=self.base_url+path
        response = self.session.delete(full_url,params=params,headers=head)
        return response.status_code,response.text,response.json()


